﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Gamego
{
    public partial class FormMain : Form
    {
        private Game game;

        public FormMain()
        {
            InitializeComponent();
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            game = new Game();
            game.gamechanged += Game_gamechanged;


        }

        private void Game_gamechanged()
        {
            if (game != null)
            {

                gameArea.Invalidate();

            }

        }

        private void gameArea_Paint(object sender, PaintEventArgs e)
        {
            if (game != null) //游戏初始化

                game.Draw(e.Graphics, this.gameArea.Size);

            if (game.GameOver())
            {
                MessageBox.Show("Game Over!");
                game = new Game();
               
                gameArea.Invalidate();
            }


        }

        private void FormMain_KeyDown(object sender, KeyEventArgs e)
        {
            if (game != null)
            {
                //传递按键值给GAME
                game.KeyDown(e.KeyCode.ToString());
                gameArea.Invalidate();


            }

        }

        private void gameArea_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            FrmAboutMe frm = new FrmAboutMe();
            frm.ShowDialog();
        }

    }
}
